from flask import Flask,render_template,abort
import json,os
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD']=True

files_dict = {}
files_list = [i[:-5] for i in os.listdir('/home/shiyanlou/files')]
for i in files_list:
    with open('/home/shiyanlou/files/'+i+'.json') as f:
        files_dict[i] = json.load(f)

@app.route('/')
def index():
        return render_template('index.html',files_list = files_list)

@app.route('/files/<filename>')
def file(filename):
        if filename not in files_dict:
                abort(404)
        return render_template('file.html', i=files_dict[filename])


@app.errorhandler(404)
def not_found(error):
        return render_template('404.html'),404

if __name__ =='__main__':

        app.run(port=3000)
